<?php
/************************************************************************
 Omnitrix - PHP Development Framework
 Copyright (C) 2012-2018 amonest(eastson@outlook.com)

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
************************************************************************/

class admin_module extends omnitrix_module
{
	public function get_info()
	{
		return array(
			'title' => 'admin',
			'description' => '',
			'website' => 'http://www.cnblogs.com/eastson/',
			'email' => 'eastson@outlook.com',
			'author' => 'amonest',
			'version' => '0.1.17'
		);
	}

	public function admin_navmenu_event($event)
	{
		$event->admin_navmenu['admin_dashboard'] = array(
			'title' => $this->_('navmenu_item_admin_dashboard'),
			'link' => 'admin.php?route=admin/dashboard'
		);
		$event->admin_navmenu['admin_system'] = array(
			'title' => $this->_('navmenu_group_admin_system'),
			'children' => array(
				'admin_module' => array(
					'title' => $this->_('navmenu_item_admin_module'),
					'link' => 'admin.php?route=admin/module'
				),
				'admin_plugin' => array(
					'title' => $this->_('navmenu_item_admin_plugin'),
					'link' => 'admin.php?route=admin/plugin'
				),
				'admin_language' => array(
					'title' => $this->_('navmenu_item_admin_language'),
					'link' => 'admin.php?route=admin/language'
				),
				'admin_theme' => array(
					'title' => $this->_('navmenu_item_admin_theme'),
					'link' => 'admin.php?route=admin/theme'
				),
				'admin_user' => array(
					'title' => $this->_('navmenu_item_admin_user'),
					'link' => 'admin.php?route=admin/user'
				),
				'admin_group' => array(
					'title' => $this->_('navmenu_item_admin_group'),
					'link' => 'admin.php?route=admin/group'
				),
				'admin_cache' => array(
					'title' => $this->_('navmenu_item_admin_cache'),
					'link' => 'admin.php?route=admin/cache'
				)
			)
		);
		$event->admin_navmenu['admin_settings'] = array(
			'title' => $this->_('navmenu_group_admin_settings'),
			'children' => array(
				'admin_config' => array(
					'title' => $this->_('navmenu_item_admin_config'),
					'link' => 'admin.php?route=admin/config'
				)
			)
		);
		$event->admin_navmenu['admin_tools'] = array(
			'title' => $this->_('navmenu_group_admin_tools'),
			'children' => array(
				'admin_phpinfo' => array(
					'title' => $this->_('navmenu_item_admin_phpinfo'),
					'link' => 'admin.php?route=admin/phpinfo'
				),
				'admin_log' => array(
					'title' => $this->_('navmenu_item_admin_log'),
					'link' => 'admin.php?route=admin/log'
				),
				'admin_backup' => array(
					'title' => $this->_('navmenu_item_admin_backup'),
					'link' => 'admin.php?route=admin/backup'
				),
				'admin_optimize' => array(
					'title' => $this->_('navmenu_item_admin_optimize'),
					'link' => 'admin.php?route=admin/optimize'
				)
			)
		);
		$event->admin_navmenu['admin_extensions'] = array(
			'title' => $this->_('navmenu_group_admin_extensions'),
			'children' => array()
		);
		$event->admin_navmenu['system_help'] = array(
			'title' => $this->_('navmenu_group_system_help'),
			'children' => array(
				'system_website' => array(
					'title' => $this->_('navmenu_item_system_website'),
					'link' => OMNITRIX_INDEX
				),
				'system_forum' => array(
					'title' => $this->_('navmenu_item_system_forum'),
					'link' => OMNITRIX_FORUM
				),
				'system_wiki' => array(
					'title' => $this->_('navmenu_item_system_wiki'),
					'link' => OMNITRIX_WIKI
				),
				'system_latest' => array(
					'title' => $this->_('navmenu_item_system_latest'),
					'link' => OMNITRIX_LATEST
				)
			)
		);
		$event->admin_navmenu['admin_frontend'] = array(
			'title' => $this->_('navmenu_item_admin_frontend'),
			'link' => 'admin.php',
			'float' => 'right'
		);
		$event->admin_navmenu['admin_logout'] = array(
			'title' => $this->_('navmenu_item_admin_logout'),
			'link' => 'admin.php?route=admin/session&action=logout',
			'float' => 'right'
		);
	}

	public function admin_configs_event($event)
	{
		$event->admin_configs['system_closed'] = array(
			'title' => $this->_('config_group_system_closed'),
			'items' => array(
				'system_closed' => array(
					'title' => $this->_('config_item_system_closed'),
					'style' => 'yesno'
				),
				'system_closed_reason' => array(
					'title' => $this->_('config_item_system_closed_reason'),
					'style' => 'textarea'
				)
			)
		);
		$event->admin_configs['system_general'] = array(
			'title' => $this->_('config_group_system_general'),
			'items' => array(
				'system_site_name' => array(
					'title' => $this->_('config_item_system_site_name'),
					'style' => 'text'
				),
				'system_site_url' => array(
					'title' => $this->_('config_item_system_site_url'),
					'style' => 'text'
				),
				'system_admin_email' => array(
					'title' => $this->_('config_item_system_admin_email'),
					'style' => 'text'
				),
				'system_default_language' => array(
					'title' => $this->_('config_item_system_default_language'),
					'style' => 'select',
					'attribs' => array(
						'options' => otx_db_fetch_pairs('SELECT language_name, language_name FROM #system_language# ORDER BY language_name')
					)
				),
				'system_crypt_salt' => array(
					'title' => $this->_('config_item_system_crypt_salt'),
					'style' => 'text',
					'generator' => array(
						'length' => 32
					)
				),
				'system_cookie_domain' => array(
					'title' => $this->_('config_item_system_cookie_domain'),
					'style' => 'text'
				),
				'system_cookie_path' => array(
					'title' => $this->_('config_item_system_cookie_path'),
					'style' => 'text'
				),
				'system_cookie_prefix' => array(
					'title' => $this->_('config_item_system_cookie_prefix'),
					'style' => 'text',
					'generator' => array(
						'length' => 8
					)
				),
				'system_page_size' => array(
					'title' => $this->_('config_item_system_page_size'),
					'style' => 'text'
				),
				'system_page_links' => array(
					'title' => $this->_('config_item_system_page_links'),
					'style' => 'text'
				)
			)
		);
		$event->admin_configs['system_server'] = array(
			'title' => $this->_('config_group_system_server'),
			'items' => array(
				'system_gzip_enabled' => array(
					'title' => $this->_('config_item_system_gzip_enabled'),
					'style' => 'yesno'
				),
				'system_nocache_headers' => array(
					'title' => $this->_('config_item_system_nocache_headers'),
					'style' => 'yesno'
				),
				'system_upload_path' => array(
					'title' => $this->_('config_item_system_upload_path'),
					'style' => 'text'
				)
			)
		);
		$event->admin_configs['system_cache'] = array(
			'title' => $this->_('config_group_system_cache'),
			'items' => array(
				'system_cache_enabled' => array(
					'title' => $this->_('config_item_system_cache_enabled'),
					'style' => 'yesno'
				),
				'system_cache_handler' => array(
					'title' => $this->_('config_item_system_cache_handler'),
					'style' => 'select',
					'attribs' => array(
						'options' => array(
							'file' => 'File'
						)
					)
				),
				'system_cache_lifetime' => array(
					'title' => $this->_('config_item_system_cache_lifetime'),
					'style' => 'text'
				)
			)
		);
		$event->admin_configs['system_session'] = array(
			'title' => $this->_('config_group_system_session'),
			'items' => array(
				'system_session_handler' => array(
					'title' => $this->_('config_item_system_session_handler'),
					'style' => 'select',
					'attribs' => array(
						'options' => array(
							'table' => 'Table'
						)
					)
				),
				'system_session_cookie' => array(
					'title' => $this->_('config_item_system_session_cookie'),
					'style' => 'text',
					'generator' => array(
						'length' => 8
					)
				),
				'system_session_lifetime' => array(
					'title' => $this->_('config_item_system_session_lifetime'),
					'style' => 'text'
				)
			)
		);
		$event->admin_configs['system_time'] = array(
			'title' => $this->_('config_group_system_time'),
			'items' => array(
				'system_date_format' => array(
					'title' => $this->_('config_item_system_date_format'),
					'style' => 'text'
				),
				'system_time_format' => array(
					'title' => $this->_('config_item_system_time_format'),
					'style' => 'text'
				),
				'system_datetime_format' => array(
					'title' => $this->_('config_item_system_datetime_format'),
					'style' => 'text'
				),
				'system_time_zone' => array(
					'title' => $this->_('config_item_system_time_zone'),
					'style' => 'select',
					'attribs' => array(
						'options' => $this->_('timezones')
					)
				)
			)
		);
		$event->admin_configs['system_email'] = array(
			'title' => $this->_('config_group_system_email'),
			'items' => array(
				'system_mail_handler' => array(
					'title' => $this->_('config_item_system_mail_handler'),
					'style' => 'select',
					'attribs' => array(
						'options' => array(
							'mail' => 'PHP mail',
							'smtp' => 'SMTP mail'
						)
					)
				),
				'system_mail_params' => array(
					'title' => $this->_('config_item_system_mail_params'),
					'style' => 'text'
				),
				'system_smtp_host' => array(
					'title' => $this->_('config_item_system_smtp_host'),
					'style' => 'text'
				),
				'system_smtp_port' => array(
					'title' => $this->_('config_item_system_smtp_port'),
					'style' => 'text'
				),
				'system_smtp_user' => array(
					'title' => $this->_('config_item_system_smtp_user'),
					'style' => 'text'
				),
				'system_smtp_pass' => array(
					'title' => $this->_('config_item_system_smtp_pass'),
					'style' => 'text'
				),
				'system_smtp_secure' => array(
					'title' => $this->_('config_item_system_smtp_secure'),
					'style' => 'select',
					'attribs' => array(
						'options' => array(
							'none' => 'None',
							'ssl' => 'SSL',
							'tls' => 'TLS'
						)
					)
				)
			)
		);
	}

	public function admin_permissions_event($event)
	{
		$event->admin_permissions['admin_module'] = array(
			'title' => $this->_('permission_group_admin_module'),
			'items' => array(
				'admin_install_module' => array(
					'title' => $this->_('permission_item_admin_install_module')
				),
				'admin_install_plugin' => array(
					'title' => $this->_('permission_item_admin_install_plugin')
				)
			)
		);
	}
}